<!-- 保养 -->
<template>
<div class="page maintain-page" id="maintain-page_{{getNewId}}" data-page="maintain" style="z-index: 2">
  <div class="link-page-nav">
      <a href="#" class="link" @click=$root.backToTab()>
          <i class="iconfont icon-zuo"></i>
      </a>
  </div>
  <div class="link-page-top">
      <div class="link-page-title" id="maintainListTitle_{{getNewId}}">保养</div>
      <div class="link-page-search">
        <div class="link-page-search-input" style="width: 66%;">
            <i class="iconfont icon-APPicon_sousuo1"></i>    
            <input type="text" placeholder="搜一搜" id="unitSearchTask_{{getNewId}}">
        </div>
      </div>
      <a class="link popover-open" data-popover="#dector_menu_{{getNewId}}">
        <i class="iconfont icon-APPicon_shaixuan1
" id="active_{{getNewId}}" style="font-size:24px"></i>
 		  </a>
  </div>
  <div class="link-page-tab">
      <div class="checkApply-tab">
          <a href="#" class="checkApply-link" @click="selectCurrentType(1)">未开始</a>
          <a href="#" class="checkApply-link active" @click="selectCurrentType(2)">进行中</a>
          <a href="#" class="checkApply-link" @click="selectCurrentType(3)">已结束</a>
      </div> 
  </div>
  <div class="page-content infinite-scroll-content ptr-content pdbottom120" style="margin-top: 0;"
        data-infinite-distance="50"  
        @infinite="loadMore" 
        @ptr:refresh="refreshMaintainList">
        <div class="ptr-preloader">
            <div class="preloader color-multi"></div>
            <div class="ptr-arrow"></div>
        </div>
        <div class="list media-list" id="historyPolice_list1_{{getNewId}}">
            <ul id="maintain_dataList_{{getNewId}}"></ul>
            <div id="dataList_preloader_{{getNewId}}" class="preloader infinite-scroll-preloader"></div>
        </div>
  </div>
  <div class="popover select-option-list" id="dector_menu_{{getNewId}}" style="width: 160px;top: 60px;">
      <div class="popover-angle"></div>
      <div class="popover-inner">
          <div class="list">
            <ul>
              <li><a href="" class="list-button item-link popover-close" id="select_org_{{getNewId}}">选择单位</a></li>
              <li><a href="" class="list-button item-link popover-close" id="select_owner_{{getNewId}}">选择责任人</a></li>
              <li>
                <a href="#" class="list-button item-link popover-close"
                  id="maintainInspect_select_progressRange_{{getNewId}}" @click="workPeriodFun">周期</a></li>
              <li>
              <!-- <li><a href="" class="list-button item-link popover-close" id="select_progressRange_{{getNewId}}" @click="rangeSlider">选择完成度</a></li> -->
              <li><a href="" class="list-button item-link popover-close" id="select_dateRange_{{getNewId}}" @click="getTbTime">选择日期范围</a></li>
              <li id="select_status_{{getNewId}}" style="height:48px;">
              	<a href="#" class="list-button item-link popover-close statusFilter" id="select_complete_{{getNewId}}"  @click="filterStatus(1)">已完成</a>
              	<a href="#" class="list-button item-link popover-close statusFilter" id="select_notComplete_{{getNewId}}"  @click="filterStatus(0)">未完成</a>
              </li>
             
              <li><a href="" class="list-button item-link popover-close removeScreen select-active" @click="removeScreen" >清&nbsp&nbsp&nbsp&nbsp&nbsp空</a></li>
            </ul>
          </div>
      </div>
  </div>
  <div class="toolbar tabbar tabbar-labels toolbar-bottom-md" id="maintain_bottom_nav_{{getNewId}}" style="height: 60px;z-index: 9999;bottom:-1px !important;display:none;">
      <div class="toolbar-inner">
          <div class="selectAll">
          	<label class="checkbox" for="selectAll_{{getNewId}}">
            	<input type="checkbox" value="0" id="selectAll_{{getNewId}}"/>
              <i class="icon-checkbox" style="    display: inline-block;
              vertical-align: middle;"></i>
              <span style="    display: inline-block;
              vertical-align: middle;">全选</span>
            </label>
          </div>
          <a href="#" class="tab-link" >
              <span class="selectNum">已选选择 <i id="selectCheckNum_{{getNewId}}">0</i> 个</span>
          </a>
          <a href="" @click="addOwner" class="tab-link">
              <div class="addOwnerBtn">添加责任人</div>
          </a>
      </div>
  </div>
</div>
</template>

<script>
return {
	mounted() {
        var self = this;
        self.tabId = this.$route.params.tabId;
        self.selectorgid = self.$route.params.orgid;
        if(!self.tabId){
          self.tabId=2;
        }
        // 选中单位
        var theOrg=currentUserUnitListData.filter(n=>{ return n.organizationId==self.selectorgid})[0]
        if(theOrg){
            jQuery("#select_org_"+self.getNewId).html(theOrg.shortName);
            jQuery("#select_org_"+self.getNewId).addClass('select-active');
        }
    },
    data: function() {
        return {
          getNewId: (new Date()).getTime(),
          pageName:"maintain",
          pageSize: 25,//分页参数(每页显示条数)
          pageIndex: 0,//分页参数
          orgIds : 0,//联网单位编码，支持多单位，逗号拼接
          status : 2,//任务状态  0:全部  1：未开始 2：进行中 3：已结束
          taskTitle : "",//任务名称
          maintainAccount: "",//责任人账号
          selectOptionOrg : "",
          currentOrgId : "",
          startPercent :"",//结束完成度
          endPercent :"",//开始完成度
          startTime :"",//开始日期 yyyy-MM-dd格式
          endTime :"",//任结束日期 yyyy-MM-dd格式
          finishStatus:"", //进行中查询的状态
          taskIds:"", //选中的任务ID
          selectOptionIndex:'',
          allowInfinite: true,
          touBType:[],
          saveListOwner:[],
          orgidArr:[],			//单位ID ，用户判断选中的任务是否是多个单位的任务
          selectOptionIndex1:null,
          selectOptionType:null,
          workPeriod:0,
        gradeselectOptionIndex:''
        }
    },
    methods: {
        backToRefresh: function () {
          var self = this;
          self.selectCurrentType(self.status);
          $("#selectCheckNum_" + self.getNewId).html(0);
        },
        // 周期选择类型
      workPeriodFun: function () {
        let self=this;
        let touBType = [{ id: 1, name: '月' }, { id: 2, name: '季度' }, { id: 3, name: '半年' }, { id: 4, name: '年' }]
        selectOptionFn(touBType, function (data) {
          if (self.workPeriod == data.id) {
            jQuery("#maintainInspect_select_progressRange_"+self.getNewId).html("周期");
            jQuery("#maintainInspect_select_progressRange_"+self.getNewId).removeClass('select-active');
            self.workPeriod = 0;
          } else {
            jQuery('#maintainInspect_select_progressRange_' + self.getNewId).html(data.name);
            jQuery('#maintainInspect_select_progressRange_' + self.getNewId).addClass('select-active');
            self.workPeriod = data.id;
          }
          if(self.gradeselectOptionIndex != data.index){
                self.gradeselectOptionIndex = data.index;
            }else{
                self.gradeselectOptionIndex = "";
            }
            jQuery("#maintain_dataList_" + self.getNewId).empty();
            self.pageIndex=0
            self.getMaintainList()
        },self.gradeselectOptionIndex);

      },
        //点击不同类型
        selectCurrentType:function(status){
          if(!getClickEnabel()) return
          let self = this;
          let $ = self.$$;
          self.status = status;
          //选择框变色
          $("#maintain-page_" + self.getNewId + " .checkApply-link").removeClass('active').eq((status-1)).addClass('active');
          $(".checkApply-page .tab-link-highlight").css("left",((status-1)==0?1:(status-1)*33.3333)+"%");
          //展示列表数据
          //显示筛选
          self.showCurrentType(status);
          self.reInit();
          self.getMaintainList();
        },
        showCurrentType:function(status){
          let self = this;
            if(status==1){
                $("#maintain_bottom_nav_" + self.getNewId).show();
                //$("#select_progressRange_" + self.getNewId).hide();
                $("#select_dateRange_" + self.getNewId).hide();
                $("#select_status_" + self.getNewId).hide();
                //初始化未开始全选
                self.initNoStart();
            }else if(status==2){
                $("#select_status_" + self.getNewId).show();// 状态
                $("#maintain_bottom_nav_" + self.getNewId).hide();//添加责任人
                //$("#select_progressRange_" + self.getNewId).hide();
                $("#select_dateRange_" + self.getNewId).hide();
            }else if(status==3){
                $("#maintain_bottom_nav_" + self.getNewId).hide();
                //$("#select_progressRange_" + self.getNewId).show();
                $("#select_status_" + self.getNewId).hide();
                $("#select_dateRange_" + self.getNewId).show();
            }
        },
        /*区分联网单位*/
        isMuilUnitUser:function(){
            var self = this;
            //单联网单位
            if (userInfor.isMuilUnitUser  == 0) {
               self.currentOrgId = userInfor.organizationIds;
               $("#select_org_" + self.getNewId).hide();
            }else{//多联网单位
               if (single_Orgid == "" &&  self.currentOrgId == -1) {
                 self.currentOrgId=userInfor.organizationIds;
               } else if(single_Orgid !=""){
                 self.currentOrgId=single_Orgid;
               }
               jQuery("#select_org_" + self.getNewId).show().click(function(e) {
                   loadSelectUnitFunc(function(data){
                      //筛选选中联网单位
                      if(self.selectOptionOrg != data.orgId){
                           self.selectOptionOrg = data.orgId;
                           self.currentOrgId=data.orgId;
                           jQuery("#select_org_" + self.getNewId).html(data.orgName);
                           // jQuery("#maintainListTitle_" + self.getNewId).html(data.orgName);
                           jQuery("#select_org_" + self.getNewId).addClass('select-active');
                      } else {
                    	   self.selectOptionOrg = '';
                           if (single_Orgid == "") {
                             self.currentOrgId=userInfor.organizationIds;
                           } else {
                             self.currentOrgId=single_Orgid;
                           }
                           jQuery("#select_org_" + self.getNewId).html("选择单位");
                           jQuery("#select_org_" + self.getNewId).removeClass('select-active');
                           //jQuery("#maintainListTitle_" + self.getNewId).html("保养");
                      }
                       self.cleanUser();
                       self.pageIndex = 0;
                       self.reInit();
                       self.getMaintainList();
                   },self.selectOptionOrg);
               });
           }
        },
        //获取维保保养任务列表
        getMaintainList:function(){
            var self = this;
            //筛选按钮有值变色
            if(jQuery('#maintainInspect_select_progressRange_'+ self.getNewId)[0].innerText!='周期'||jQuery("#select_owner_" + self.getNewId)[0].innerText != "选择责任人" || self.startTime!= "" || self.startPercent!="" || jQuery("#select_org_" + self.getNewId)[0].innerText != "选择单位" || self.finishStatus != "" || self.finishStatus === 0){
              jQuery("#active_" + self.getNewId).addClass("select-active");
            }else{
              jQuery("#active_" + self.getNewId).removeClass("select-active");
            }
            self.saveListOwner = [];
            Dao.getMainTainTaskList({
              queryType: 1,//分页参数 0：不分页 1：分页
              pageSize: self.pageSize,//分页参数(每页显示条数)
              pageIndex:self.pageIndex,//分页参数
              orgIds:self.currentOrgId,//self.currentOrgId  122 测试数据先写死  联网单位编码，支持多单位，逗号拼接  
              status:self.status,//任务状态 1：未开始 2：进行中 3：已结束
              maintainAccount:self.maintainAccount,//责任人账号
              name:self.taskTitle,//任务名称
              startPercent:self.startPercent,//开始完成度
              endPercent:self.endPercent,//结束完成度
              startTime:self.startTime,//开始日期 yyyy-MM-dd格式
              endTime:self.endTime,//任结束日期 yyyy-MM-dd格式
              finishStatus : self.finishStatus,
              maintainType: 2,  //1 维保巡查任务 2保养任务 3测试任务 4联动测试任务
              account:userInfor.accountName,
              workPeriod:self.workPeriod
            }, function (data,total) {
                if (data && data.length > 0){
                  if (self.pageSize * self.pageIndex + data.length < total) { //有分页
                      $("#dataList_preloader_" + self.getNewId).show();
                      self.allowInfinite = true;
                  } else {  //没分页
                      $("#dataList_preloader_" + self.getNewId).hide();
                      self.allowInfinite = false;
                  }
                  for (var i=0;i<data.length;i++) {
                    //保存责任人
                    if(data[i].maintainAccount){
                        self.saveListOwner[data[i].id] = data[i].maintainAccount;
                    }
                    var maintainNames = data[i].maintainNames==null?"无":data[i].maintainNames;//任务责任人名称
                    var assetsCount = data[i].assetsCount; //资产数量
                    var finishCount = data[i].finishCount; //维保完成数量
                   
                    var percentage = "0%";
                    let percentageRealNum = 100;
                    let percentageNum = Math.round((finishCount/assetsCount).toFixed(2)*100);
                    if(!isNaN(percentageNum)){
                       percentageRealNum = percentageNum-100;
                        percentage = Math.round((finishCount/assetsCount).toFixed(2)*100).toString()+"%";
                    }
                    
                    var orgNameHtml = "";
                    var status = "未完成";
                    var statusCSS = "title-status-notComplete";
                    if(percentage =="100%"){
                        status="完成";
                        statusCSS = "title-status-complete";
                    }
                    if(userInfor.isMuilUnitUser  == 1){
                        orgNameHtml = `<div class="item-subtitle decter-belong-unit">
                                        <i class="iconfont icon-dingweiweizhi" style="color: #2471CA;font-size: 14px;"></i>
                                        `+data[i].orgName+`
                                      </div>`;
                    }
                    if(self.status==2){//进行中的任务
                        $("#maintain_dataList_" + self.getNewId).append(`
                          <li style="overflow:hidden">
                            <a href="/maintainDetail/`+data[i].id+`/0/" class="item-link item-content" data-view=".view-main">
                              <div class="item-inner">
                                <div class="item-title-row">`+data[i].name+`</div>
                                <div class="item-subtitle decter-mesage">
                                  <div class="ilink-progress-len-title">完成进度</div>
                                  <div class="ilink-progress-len">
                                  <div class="ilink-progress-left">
                                    <div data-progress="80" class="progressbar color-blue progressbar-height">
                                      <span style="transform: translate3d(`+ percentageRealNum + `%, 0px, 0px);" class=""></span>
                                    </div>
                                  </div>
                                  <div class="progressbarNum">`+ percentage + `</div>
                                </div> 
                                </div>
                                <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+maintainNames+`</div>
                                `+orgNameHtml+`
                              </div>
                            </a>
                            <div class="decter-stuts-con" style="padding-left: 15px;">
                              <span class="left">
                                <span>`+isDay(data[i].remainTime)+`</span>
                              </span>
                           
                            </div>
                            <span class="right" style="display:block;width:80px;text-align:center;background:#2196f3;margin:15px 15px 10px;border-radius:15px;float:right;font-size:12px;">
                                 <a href="#" id="task_`+ (self.getNewId + '_' + data[i].id) +`" style="color:#fff;display:block;padding:5px 0;" data-view=".view-main" ></a>
                              </span>
                          </li>`);
                     
                      if(percentage =="100%"){
                    	  $("#task_"+ (self.getNewId + '_' + data[i].id)).parent('span').hide();
                      }else{
                    	  // 设置任务
                          var dataTask = {
                        	"id": data[i].id,
                        	"orgId":data[i].orgId,
                          "orgName":data[i].orgName,
                        	"name":data[i].name,
                        	"status":data[i].status,
                        	"testTaskStatus":data[i].testTaskStatus,
                        	"maintainAccount":data[i].maintainAccount,
                          };
                    	  self.sortTask(dataTask);
                      }
                    }
                    else if(self.status==1){//未开始的任务
                      $("#maintain_dataList_" + self.getNewId).append(`
                          <li>
                            <a href="/maintainDetail/`+data[i].id+`/0/" class="item-link item-content" data-view=".view-main">
                              <div class="item-inner">
                                <div class="item-title-row">`+data[i].name+`</div>
                                <div class="item-subtitle decter-mesage">
                                  <div style="float: left;">任务周期</div>
                                  <div class="taskCycleDate">`+data[i].startTimeStr+`~`+data[i].endTimeStr+`</div>
                                </div>
                                <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+maintainNames+`</div>
                                `+orgNameHtml+`
                              </div>
                            </a>
                            <div class="decter-stuts-con" style="padding-left: 15px;">
                              <span class="left">
                                <label class="checkbox dataList-checkbox">
                                      <input type="checkbox" value="`+data[i].id+`" data-orgid="`+data[i].orgId+`"/>
                                      <i class="icon-checkbox"></i>
                                    </label>
                              </span>
                              <span class="startTime">`+data[i].remainTime+`&nbsp;后开始</span>
                            </div>
                          </li>`);
                    }
                    else if(self.status==3){//已完成的任务
                       $("#maintain_dataList_" + self.getNewId).append(`
                          <li>
                          <a href="/maintainDetail/`+data[i].id+`/0/" class="item-link item-content" data-view=".view-main">
                            <div class="item-inner">
                              <div class="`+statusCSS+`">`+status+`</div>
                              <div class="item-title-row protect-title">`+data[i].name+`</div>
                              <div class="item-subtitle decter-mesage">
                                <div style="float: left;">完成进度</div>
                                <div class="ilink-progress-len">
                                  <div class="ilink-progress-left">
                                    <div data-progress="80" class="progressbar color-blue progressbar-height">
                                      <span style="transform: translate3d(`+ percentageRealNum + `%, 0px, 0px);" class=""></span>
                                    </div>
                                  </div>
                                  <div class="progressbarNum">`+ percentage + `</div>
                                </div> 
                              </div>
                              <div class="item-subtitle decter-mesage">
                              <div style="float: left;">任务周期</div>
                              <div class="taskCycleDate">`+data[i].startTimeStr+`~`+data[i].endTimeStr+`</div>
                            </div>
                              <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+maintainNames+`</div>
                              `+orgNameHtml+`
                            </div>
                          </a>
                        </li>`);
                    }
                  }
                  if(self.status==1){
                    self.getSelectCheckBox();
                  }
                }else{
                  self.allowInfinite = false;
                  $("#dataList_preloader_" + self.getNewId).hide();
                  //暂无数据
                  if (self.pageIndex == 0) {
                      $("#maintain_dataList_" + self.getNewId).append(`<div class="no-data-img"><img src="`+listNoDataPic()+`"/></div>`);
                  }
                }
            });
        },
        sortTask:function(data) {
        	var self = this;
        	if(data.maintainAccount.indexOf(userInfor.accountName)>=0){//当前登录人是责任人
	        	if(data.testTaskStatus == 0) { //开始保养
	        		jQuery("#task_"+ (self.getNewId + '_' + data.id)).html(`开始保养 `);
	        	} else {  // 继续保养
	        		jQuery("#task_"+ (self.getNewId + '_' + data.id)).html(`继续保养 `);
	        	}
        	}else{
            $("#task_" + (self.getNewId + '_' + data.id)).parent('span').hide();
          }
        	jQuery("#task_"+ (self.getNewId + '_' + data.id)).off().click(data,function(e){
        		if(e.data.testTaskStatus == 0) {
        			Dao.startTestTask({
    					   taskId:e.data.id,
    					   account:userInfor.accountName
    				  },function(data){
      					app.methods.showToastCenter("加入成功");
      					self.getMaintainList(); // 刷新列表数据
      					custom.startMaintenancePlan();
      					app.router.navigate(`/allBuild/maintain/`+e.data.id+`/`+e.data.orgName+`/`+encodeURIComponent(e.data.name)+`/`+e.data.status+`/`+e.data.orgId+`/`);
    				  },true);
        		} else {
        			app.router.navigate(`/allBuild/maintain/`+data.id+`/`+data.orgName+`/`+encodeURIComponent(data.name)+`/`+data.status+`/`+data.orgId+`/`);
        		}
        	}); 
        },
        //清空
        removeScreen:function(){
            var self = this;
            jQuery("#select_org_" + self.getNewId).removeClass('select-active').html("选择单位");
            jQuery("#select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
            jQuery("#maintainInspect_select_progressRange_" + self.getNewId).removeClass('select-active').html("周期");
            //jQuery("#maintainListTitle_" + self.getNewId).html("保养");
            jQuery("#unitSearchTask_" + self.getNewId).val(null);
            self.maintainAccount = "";
            self.taskTitle = "";
            self.startPercent = "";
            self.endPercent = "";
            self.startTime = "";
            self.endTime = "";
            self.finishStatus = "";
            self.selectOptionIndex = 0;
            self.pageIndex = 0;
            self.selectOptionOrg = '';
            self.workPeriod=0
            self.gradeselectOptionIndex=''
            jQuery("#select_dateRange_" + self.getNewId).html("选择日期范围").removeClass('select-active');
            $("#select_complete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
            $("#select_notComplete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
            if (userInfor.isMuilUnitUser  == 0) {
              self.currentOrgId = userInfor.organizationIds;
            }else{
              //多联网单位
              if (single_Orgid == "") {
                self.currentOrgId=userInfor.organizationIds;
              } else {
                self.currentOrgId=single_Orgid;
              }
            }
            self.reInit();
            self.getMaintainList();
        },
        /*责任人*/
        htmlGetUnitUsers:function(){
            var self = this;
            self.selectOptionIndex1 = null;
            self.selectOptionType = null;
            //人员名单
            jQuery("#select_owner_" + self.getNewId).click(function(e) {
              /* if(!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1){
                  app.methods.showToastCenter('请选择单位');
                  return;
              } */
            	getFourTypeUser(self.currentOrgId,function(data){
                    //这里是选择责任人之后的回调
                    if(self.selectOptionIndex1 != data.index){
                        self.selectOptionIndex1 = data.index;
                        self.selectOptionType = data.type;
                        //维保公司 这下面判断什么意思？
                        // if(data.type == 4){
                        //   self.maintainAccount = '';
                        // }else{
                        //   self.maintainAccount = data.index;
                        // }
                        self.maintainAccount = data.index;
                        $("#select_owner_" + self.getNewId).addClass('select-active').html(data.name);
                    }else{
                        self.selectOptionIndex1 = "";
                        self.selectOptionType = 1;
                        self.maintainAccount = "";
                        $("#select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
                    }  
                    self.pageIndex = 0;
                    self.reInit();
                    self.getMaintainList();
                },self.selectOptionIndex1,self.selectOptionType);
            });
        },
        //清除责任人相关参数
        cleanUser:function(){
            var self = this;
            self.selectOptionIndex1 = null;
            self.selectOptionType = null;
            self.maintainAccount = "";
            jQuery("#select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
        },
        dealNode:function(re){
          let self = this;
          for(var i=0;i<re.length;i++){
            let obj = {};
            obj.id= re[i].id;
            obj.name= re[i].name;
            obj.type= 'weibaogongsi';
            self.touBType.push(obj);
            if(re[i].nodes && re[i].nodes.length>0){
              self.dealNode(re[i].nodes);
            }
          }
        },
        //全选
        initNoStart:function(){
          let self = this;
          $("#selectAll_" + self.getNewId).change(function(){
              self.taskIds="";
              self.orgidArr = [];
              if($("#selectAll_" + self.getNewId).prop("checked")){
                  $("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input").prop("checked", true);
                  $("#selectCheckNum_" + self.getNewId).html($("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input").length);
              }else{
                  $("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input").prop("checked", false);
                  $("#selectCheckNum_" + self.getNewId).html(0);
              } 
              let checkOwner = $("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input:checked");
              let taskIdsStr = ""
              for ( let i = 0; i <checkOwner.length; i++){
            	 self.orgidArr.push($(checkOwner[i]).attr("data-orgid")); 
                 let taskId = $(checkOwner[i]).val();
                 if(i<checkOwner.length-1){
                   taskId=taskId+",";
                 }
                 self.taskIds+=taskId;
              }
          });
        },
        //单个复选框选中事件
        getSelectCheckBox:function(){
          var self = this;
          self.taskIds="";
          $("#selectAll_" + self.getNewId).prop("checked", false);
          $("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input").change(function(e) {
              self.taskIds="";
              self.orgidArr = [];
              var chks=$("#maintain_dataList_" + self.getNewId +" input:checked").length;
              $("#selectCheckNum_" + self.getNewId).html(chks);
              if($("#maintain_dataList_" + self.getNewId +" .dataList-checkbox input").length==chks){
                $("#selectAll_" + self.getNewId).prop("checked", true);
              }else{
                $("#selectAll_" + self.getNewId).prop("checked", false);
              }
              var checkOwner = $("#maintain_dataList_" + self.getNewId +" input:checked");
              var taskIdsStr = ""
              for ( var i = 0; i <checkOwner.length; i++){
            	  	self.orgidArr.push($(checkOwner[i]).attr("data-orgid")); 
	                var taskId = $(checkOwner[i]).val();
	                if(i<checkOwner.length-1){
	                  taskId=taskId+",";
	                }
	                self.taskIds+=taskId;
              }
          });
        },
        //完成范围进度条范围
        /* rangeSlider:function(){
           var self = this;
           var html=`<div class="block-title display-flex justify-content-space-between">范围 <span class="price-value" id="filter_rangeSlider_` + self.getNewId +`">20 - 80</span></div>
                 <div class="list simple-list">
                 <ul>
                 <li class="item-row">
                   <div class="item-cell width-auto flex-shrink-0">
                   </div>
                   <div class="item-cell item-cell-shrink-3">
                     <div
                       id="price_filter_v_`+ self.getNewId +`"
                       class="range-slider range-slider-init color-green"
                       data-label="true"
                       data-dual="true"
                       data-min="0"
                       data-max="100"
                       data-step="1"
                       data-value-left="20"
                       data-value-right="80"
                     ></div>
                   </div>
                   <div class="item-cell width-auto flex-shrink-0">
                   </div>
                 </li>
               </ul>
             </div>`;
            layer.open({content: html
              ,success:function(){
                     var range = app.range.create({
                         el: '#price_filter_v_'+ self.getNewId ,
                         on: {
                           change: function () {
                            
                           }
                         }
                       })
                     },btn: ['确定']
                     ,yes: function(index, layero){
                       self.startPercent = $("#filter_rangeSlider_" + self.getNewId).html().split(" - ")[0];
                       self.endPercent = $("#filter_rangeSlider_" + self.getNewId).html().split(" - ")[1];
                       self.pageIndex = 0;
                       self.reInit();
                       self.getMaintainList();
                       layer.closeAll();
                     }
            }); 
            $('#price_filter_v_'+ self.getNewId ).on('range:change', function (e, range) {
                $("#filter_rangeSlider_" + self.getNewId).text((range.value[0])+' - '+(range.value[1]));
            });
        }, */
        //时间筛选
        getTbTime:function(){
            var self = this;
            //type 0:年 1:年月 2：月日
            loadSelectedDate_Fn(4,function(data){
            	    self.startTime = data.startTime;
                    self.endTime = data.endTime;
                    var tempTimeYear = new Date(data.startTime.replace(/\-/g, "/")).getFullYear()+'年';
                    var tempTimeMonth = (new Date(data.startTime.replace(/\-/g, "/")).getMonth()+1)+'月'
                    $("#select_dateRange_" + self.getNewId).addClass('select-active').html(tempTimeYear+tempTimeMonth);
                    $("#maintain_dataList_" + self.getNewId).empty();
                    self.pageIndex = 0;
                    //self.reInit();
                    self.getMaintainList();
                },self.startTime);
        },
        /*初始化搜索*/
        searchTask:function(){
          var self = this;
          jQuery("#unitSearchTask_" + self.getNewId).keypress(function(e) {
              let name = jQuery("#unitSearchTask_" + self.getNewId).val();
              if (e.which == 13) {
                  self.taskTitle = name;
                  self.pageIndex = 0;
                  self.reInit();
                  self.getMaintainList();
              };
          });
        },
        addOwner:function(){
            var self = this;
            if(self.taskIds==""){
                app.methods.showToastCenter('请选择任务');
                return;
            }else{
            	var tempOrgids=[];
           	  	for (var i = 0; i < self.orgidArr.length; i++) {
    	       	     if(self.orgidArr.indexOf(self.orgidArr[i])==i){
    	       	    	 tempOrgids.push(self.orgidArr[i]);
    	       	     }
           	  	}
           		//如果用户选择了多个单位的维保任务，则提示用户“请选择同一单位的维保任务”;
           	  	if(tempOrgids.length>1){
                 	app.methods.showToastCenter('请选择同一单位的维保任务');
                 	return;
           	  	}
           	 	app.router.navigate("/maintainOwner/"+tempOrgids[0]+"/"+self.taskIds+"/maintain/"+self.getCurrentOwner()+"/");
            }
        },
        //获取当前勾选的责任人
        getCurrentOwner:function(){
            let self = this;
            let hasOwnerEl = $("#maintain_dataList_" + self.getNewId +" input[type=checkbox]:checked");
            let ownerId = [-1];
            //单个任务才带责任人过去
            if(hasOwnerEl.length==1){
          	  let currentOwner = self.saveListOwner[hasOwnerEl[0].value];
          	  if(currentOwner){
          		  ownerId = [currentOwner]
          	  }
            }
            return ownerId.toString();
        },
        //筛选 完成/未完成
        filterStatus:function(type){
          if(!getClickEnabel()) return
          var self = this;
          self.pageIndex = 0;
          self.finishStatus=type;
          if(type==1){
            $("#select_complete_" + self.getNewId).removeClass('statusFilter').addClass("selectStatusFilter");
            $("#select_notComplete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
          }else{
            $("#select_complete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
            $("#select_notComplete_" + self.getNewId).removeClass('statusFilter').addClass("selectStatusFilter");
          }
          self.reInit();
          self.getMaintainList();
        },
        loadMore:function(){
          var self = this;
          if (!self.allowInfinite) return;
            self.allowInfinite = false;
          setTimeout(function () {
            self.pageIndex++;
            self.getMaintainList();
            self.allowInfinite = true;
              }, 1000);
        },
        reInit:function(){
            var self = this;
            self.pageIndex = 0;
            $("#selectAll_" + self.getNewId).prop("checked", false);
            if (app.view.current.router.url.indexOf('/maintain/') > -1) {//防止子页面返回触发。有类似的需求可以往这个里面添加
              $("#maintain-page_" + self.getNewId + " .page-content").scrollTop(0, 300);
            }
            $("#maintain_dataList_" + self.getNewId).empty();
            if(!self.allowInfinite){
                self.allowInfinite = true;
                $("#dataList_preloader_" + self.getNewId).show();
            }
        },
        refreshMaintainList: function (e, done) {
            if (done && e) {
                var self = this;
                var $ = self.$$;
                setTimeout(function () {
                    self.reInit();
                    $("#dataList_preloader_" + self.getNewId).hide();
                    self.getMaintainList();
                    done();
                }, 1000);
            }
        },
        //维保助手里面结束任务后，如果当前是在列表页面（保养，维保巡查，单点测试，联动测试）要刷新当前列表
        closeTaskBackRefreshList: function (e, done) {
            var self = this;
            var $ = self.$$;
            self.reInit();
            $("#dataList_preloader_" + self.getNewId).hide();
            self.getMaintainList();
        },
    },
    on: {
        pageInit: function(e, page) {
            var self = this;
            var $ = self.$;
            self.pageIndex = 0;
            if(self.selectorgid == -1){
              self.currentOrgId = userInfor.organizationIds;
            }else{
              self.currentOrgId = self.selectorgid;
            }
            //self.reInit();
            //区分联网单位
            self.isMuilUnitUser();
            //重现筛选条件
            if(localStorage.getItem("ilink_select_option")){
                var selectHistory = JSON.parse(localStorage.getItem("ilink_select_option"));
                if(selectHistory.page == "maintain"){
                    self.currentOrgId = selectHistory.organizationIds;
                    jQuery("#select_org_" + self.getNewId).html(selectHistory.orgName).addClass('select-active');
                }
            }
            //防止看板点击进来页面闪烁
            setTimeout(function (){
              self.selectCurrentType(self.tabId);
              //初始化搜索
              self.searchTask();
              //责任人
              self.htmlGetUnitUsers();
            }, 100);
            //列表
            //self.getMaintainList();
        },
        pageBeforeOut: function(e, page) {
            var self = this;
            if(self.currentOrgId != userInfor.organizationIds){
                let params = {
                    page:'maintain',
                    organizationIds:self.currentOrgId,
                    orgName:jQuery("#select_org_" + self.getNewId).html(),
                }
                saveSelectOption(params);
            }
        }
    }
}
</script>